home *** CD-ROM | disk | FTP | other *** search
Text File | 1999-03-04 | 4.3 KB | 209 lines | [TEXT/ToyS] |
- -- Properties
- property kasPrefName : "S&R Names V1.0"
-
- -- Globals
- global gasInfoWind -- Info window
- global gasInfoPos -- Position of info window
-
- global gasFoldersToDo -- The folders left to process
- global gasChecked -- Number checked!
- global gasChanged -- Number changed
-
- global gasSearch -- Search string
- global gasReplace -- Replace with
- global gasDoRsrc, gasDoData
-
-
- on open fsObjs
- -- Load prefs, show window
- pfLoad()
-
- -- Set up prefix
- set gasChecked to 0
- set gasChanged to 0
-
- GetInputs()
-
- set gasInfoWind to display info titled kasPrefName ¬
- located at gasInfoPos ¬
- message "Scanning…"
-
- display info gasInfoWind ¬
- message ("Search: " & gasSearch) ¬
- at line 8
-
- display info gasInfoWind ¬
- message ("Replace: " & gasReplace) ¬
- at line 9
-
- -- Do files
- set gasFoldersToDo to {}
-
- repeat with fsObj in fsObjs
- set myInfo to (basic info for fsObj)
-
- if (system type of myInfo is "fold") then
- set gasFoldersToDo to gasFoldersToDo & {fsObj}
- else
- DoOne(fsObj)
- end if
- end repeat
-
- -- Do folders
- repeat while gasFoldersToDo is not {}
- -- Pop one off the end
- set n to the number of items of gasFoldersToDo
- set fsObj to item n of gasFoldersToDo
-
- if (n > 1) then
- set gasFoldersToDo to items 1 through (n - 1) of gasFoldersToDo
- else
- set gasFoldersToDo to {}
- end if
-
- display info gasInfoWind ¬
- message ("Folders to go: " & n) ¬
- at line 6 ¬
- using color (15 * 32)
-
- -- Process it
- DoOne(fsObj)
- GoDeep(fsObj)
- end repeat
-
- display info gasInfoWind message "DONE!"
-
- pause for 3 with seconds timing -- Let screen wait...
-
- set gasInfoPos to screen location of ¬
- (display info gasInfoWind with disposal)
-
- pfSave() -- Save window location
- end open
-
-
- on GetInputs()
- set gasSearch to GetString("search string", gasSearch)
- set gasReplace to GetString("replace string", gasReplace)
- end GetInputs
-
-
- on GetString(sName, sDef)
- return text returned of ¬
- (display dialog ("Enter the " & sName & ":") ¬
- buttons {"Cancel", "OK"} ¬
- default answer sDef ¬
- default button 2 ¬
- with icon note)
- end GetString
-
-
- on ShowAlert(msg)
- return button returned of ¬
- (display dialog msg ¬
- buttons {"Cancel", "Yo!"} ¬
- default button 2 ¬
- with icon stop)
- end ShowAlert
-
-
- on ShowChoice(msg, choices)
- return button returned of ¬
- (display dialog msg ¬
- buttons choices ¬
- default button (number of items of choices) ¬
- with icon caution)
- end ShowChoice
-
-
- on DoOne(fsObj)
- set fInfo to (basic info for fsObj)
- set fname to (catalog name of fInfo)
-
- set gasChecked to gasChecked + 1
-
- display info gasInfoWind ¬
- message fname ¬
- at line 2
-
- set newName to munge fname ¬
- searching for gasSearch ¬
- replacing it with gasReplace
-
- if (newName is not fname) then
- display info gasInfoWind ¬
- message ("Renaming") ¬
- at line 4
- try
- collate fsObj ¬
- renaming it to newName
- on error err
- display info gasInfoWind ¬
- message ("Error: " & err) ¬
- at line 15
- end try
- set gasChanged to gasChanged + 1
- end if
-
- display info gasInfoWind ¬
- message ("Checked: " & gasChecked) ¬
- at line 12
- display info gasInfoWind ¬
- message ("Changed: " & gasChanged) ¬
- at line 13
- end DoOne
-
-
- on GoDeep(foldObj)
- display info gasInfoWind ¬
- message "Path: " & (foldObj as string)
-
- set daddy to foldObj as string
-
- -- Do kinds that match
- display info gasInfoWind ¬
- message "Scanning files" at line 5
-
- set myItems to the entries in foldObj ¬
- whose kinds are a file
-
- repeat with myItem in myItems
- DoOne((daddy & myItem) as alias)
- end repeat
-
- -- Do folders
- display info gasInfoWind ¬
- message "Scanning subfolders" at line 5
-
- set myItems to the entries in foldObj ¬
- whose kinds are a folder
-
- repeat with myItem in myItems
- set gasFoldersToDo to gasFoldersToDo & {(daddy & myItem) as alias}
- end repeat
-
- -- Done
- display info gasInfoWind ¬
- message "…" at line 5
- end GoDeep
-
-
- on pfLoad()
- try
- set ourPrefs to (load preference named kasPrefName)
- on error
- set ourPrefs to {{8, 48}, ">LORE<", "◊LIFE◊", true, true}
- end try
-
- set gasInfoPos to item 1 of ourPrefs
- set gasSearch to item 2 of ourPrefs
- set gasReplace to item 3 of ourPrefs
- set gasDoData to item 4 of ourPrefs
- set gasDoRsrc to item 5 of ourPrefs
- end pfLoad
-
-
- on pfSave()
- save preference {gasInfoPos, gasSearch, gasReplace, gasDoData, gasDoRsrc} named kasPrefName
- end pfSave
-